<template>
  <view class="tabbar">
    <view class="tab-item">
      <image src="https://fuqiaohui.oss-cn-chengdu.aliyuncs.com/merchant/set.png" mode="" class="img"></image>
      <view class="set">建设中</view>
    </view>
    <view class="active center" @click="goCode">
      <image src="https://fuqiaohui.oss-cn-chengdu.aliyuncs.com/merchant/code.png" mode="" class="active-img"></image>
    </view>
    <view class="tab-item">
      <image src="https://fuqiaohui.oss-cn-chengdu.aliyuncs.com/merchant/my.png" mode="" class="img"></image>
      <view class="my">我的</view>
    </view>
  </view>
</template>

<script>
export default {
  name: "tabbar",
  data() {
    return {
      token: uni.getStorageSync("token") || ""
    }
  },
  methods: {
    async isLogin() {
      return new Promise((resolve, reject) => {
        if (!this.token) {
          return uni.showModal({
            title: "暂未登录",
            content: "是否现在去登录",
            success: res => {
              if (res.confirm) {
                this.goLogin()
              } else if (res.cancel) {
                console.log("用户点击取消")
              }
            }
          })
        } else {
          return resolve()
        }
      })
    },
    goLogin() {
      uni.navigateTo({
        url: "/pages/login/login"
      })
    },
    async goCode() {
      await this.isLogin()
      uni.navigateTo({
        url: "/pages/code/code"
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100vw;
  height: 140rpx;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 110rpx;
}

.tab-item {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.active {
  margin-bottom: 80rpx;
}

.active-img {
  width: 130rpx;
  height: 130rpx;
}

.img {
  width: 40rpx;
  height: 40rpx;
  margin-bottom: 6rpx;
}

.set {
  font-size: 26rpx;
  color: #b9b9b9;
}

.my {
  font-size: 26rpx;
  color: #114f9e;
}
</style>
